<?php

class Crud {
	
	public static function generateView($layout, $view, $module) {
		if(!file_exists(app_path() . '/views/' . $view . '-' . $module . '.blade.php')) {
			$content = file_get_contents(app_path() . '/views/layout/' . $layout . '/' . $module . '.blade.php', 'r');
			$fp = fopen(app_path() . '/views/' . $view . '-' . $module . '.blade.php', 'w+');
			fwrite($fp, $content);
			fclose($fp);

			return $view . '-' . $module;
		}
		return $view . '-' . $module;
	}

	public static function genearateModel($table, $model) {
		if(!file_exists(app_path() . '/models/' . $model . '.php') && ($table != '[]' && $table != '') && ($model != '[]' && $model != '')) {
			$content  = "<?php\n\n";
			$content .= "use Illuminate\Database\Eloquent\SoftDeletingTrait;\n\n";
			$content .=	"class " . $model . " extends Eloquent {\n\n";
			$content .= "\t use SoftDeletingTrait;\n\n";
			$content .= "\t protected \$dates = ['deleted_at']\n\n;";
			$content .= "\t protected \$table = '$table';\n\n";
			$content .= "}";
	
			$fp = fopen(app_path() . '/models/' . $model . '.php', 'w');
			fwrite($fp, $content);
			fclose($fp);
		}
	}

	public static function generateLanguage($local, $name) {
		if(!file_exists(app_path() . '/lang/' . $local . '/' . $name . '.php')) {
			$content = file_get_contents(app_path() . '/lang/' . $local . '/default.php', 'r');
			$content = str_replace('Title', ucwords($name), $content);
			$fp = fopen(app_path() . '/lang/' . $local . '/' . $name . '.php', 'w+');
			fwrite($fp, $content);
			fclose($fp);
		}
	}
}